package main

import (
	"fmt"
	"time"
)

func sleepTask(sleepTime int) {
	time.Sleep(time.Second * time.Duration(sleepTime))
}

func main() {
	var a int = 2
	taskOne(&a)
	fmt.Println("a的值是", a)

	/* 切片乘以2*/
	nums := []int{1, 2, 3, 4, 5}
	taskTwo(&nums)
	fmt.Println("nums的值是", nums)

	taskThree()
	wg.Wait()

	// 1. 定义一批“任务”——这里用睡眠模拟不同耗时
	funList := []func(){
		func() { time.Sleep(200 * time.Millisecond) },
		func() { time.Sleep(500 * time.Millisecond) },
		func() { time.Sleep(100 * time.Millisecond) },
		func() { time.Sleep(300 * time.Millisecond) },
	}

	TaskFour(funList)

	r := Rectangle{Width: 10, Height: 20}
	fmt.Println("长方形周长是", r.Perimeter(), "面积是", r.Area())

	c := Circle{Radius: 10}
	fmt.Println("正方形周长是", c.Perimeter(), "面积是", c.Area())

	e := Employee{Person{"张三", 18}, 1}
	e.PrintInfo()

	/*通道的基本使用、协程间通信。
	 */
	ch := make(chan int, 10)
	go producer(ch, 100)
	consumer(ch)

	toal := lockCounter(0)
	fmt.Println("加锁最后的值为", toal)

	var counter int64 = 0
	toal2 := lockCounter2(counter)
	fmt.Println("原子操作最后的值", toal2)

}
